import java.util.Scanner;

public class Test4 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int[] firtMax = new int[n];
        int[] secondMax = new int[n];
        firtMax[0] = nums[0];
        secondMax[0] = -0x3f3f3f3f;
        for (int i = 1; i < n; i++) {
            if (nums[i] > firtMax[i-1]) {
                firtMax[i] = nums[i];
                secondMax[i] = firtMax[i-1];
            } else if (nums[i] == firtMax[i-1]) {
                firtMax[i] = secondMax[i] = nums[i];
            } else {
                firtMax[i] = firtMax[i-1];
                if (nums[i] >= secondMax[i-1]) {
                    secondMax[i] = nums[i];
                } else {
                    secondMax[i] = secondMax[i-1];
                }
            }
        }
        int q = in.nextInt();
        while (q-- > 0) {
            int tmp = in.nextInt();
            System.out.println(secondMax[tmp-1]);
        }
    }

    /**
     * 空间优化：因为最大值只是用来辅助寻找第二大的数，所以可以只保存最大值和第二大的值
     * @param args
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int[] secondMax = new int[n];
        secondMax[0] = -0x3f3f3f3f;
        int max = nums[0];
        for (int i = 1; i < n; i++) {
            if (nums[i] > max) {
                secondMax[i] = max;
                max = nums[i];
            } else if (nums[i] == max) {
                max = secondMax[i] = nums[i];
            } else {
                if (nums[i] >= secondMax[i-1]) {
                    secondMax[i] = nums[i];
                } else {
                    secondMax[i] = secondMax[i-1];
                }
            }
        }
        int q = in.nextInt();
        while (q-- > 0) {
            int tmp = in.nextInt();
            System.out.println(secondMax[tmp-1]);
        }
    }
}
